package
{
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import mx.events.MoveEvent;
	
	import org.osmf.layout.AbsoluteLayoutFacet;

	public class buton extends MovieClip
	{
		var numeButon:TextField=new TextField();
		
		var bWidth:int=45;
		var bHeight:int=20;
		
		var tWidth:int=44;
		var tHeight:int=18;
		
		public function buton()
		{
			initializare();
			
			this.addEventListener(Event.ADDED_TO_STAGE,addedToStage);
		}
		
		private function addedToStage(e:Event):void
		{
			this.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
			this.addEventListener(MouseEvent.MOUSE_OVER,mouseOver);
		}
		
		private function mouseDown(e:MouseEvent):void
		{
			this.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
			this.addEventListener(MouseEvent.MOUSE_OUT,mouseUp);
			
			deseneazaApasat();
		}
		
		private function mouseUp(e:MouseEvent):void
		{
			this.removeEventListener(MouseEvent.MOUSE_OUT,mouseUp);
			this.removeEventListener(MouseEvent.MOUSE_UP,mouseUp);
			
			deseneaza();
		}
		
		private function mouseOver(e:MouseEvent):void
		{
			this.addEventListener(MouseEvent.MOUSE_OUT,mouseOut);
			
			deseneazaDeasupra();
		}
		
		private function mouseOut(e:MouseEvent):void
		{
			this.removeEventListener(MouseEvent.MOUSE_OUT,mouseOut);
			
			deseneaza();
		}
		
		private function deseneaza():void
		{
			this.graphics.clear();
			
			this.graphics.beginFill(0x00adee,0.9);
			this.graphics.drawRoundRect(0,0,bWidth,bHeight,5,5);
		}
		
		private function deseneazaApasat():void
		{
			this.graphics.clear();
			this.graphics.beginFill(0x0aaaaa,0.9);
			this.graphics.drawRoundRect(0,0,bWidth,bHeight,5,5);
		}
		
		private function deseneazaDeasupra():void
		{
			this.graphics.clear();
			
			this.graphics.beginFill(0x0dabb,0.9);
			this.graphics.drawRoundRect(0,0,bWidth,bHeight,5,5);
		}
		
		public function set valid(e:Boolean):void
		{
			if(e==true)
			{
				this.mouseEnabled=true;
			}
			else
			{
				this.mouseEnabled=false;
			}
		}
		
		private function initializare():void
		{	
			deseneaza();
			
			numeButon.x=1;
			numeButon.y=1;
			
			numeButon.width=tWidth;
			numeButon.height=tHeight;
			
			numeButon.mouseEnabled=false;
			
			this.addChild(numeButon);
		}
		
		public function set nume(s:String):void
		{
			numeButon.text=s;
		}
		
		public function set culoare(c:uint):void
		{
			numeButon.textColor=c;
		}
	}
}